package com.atguigu.tingshu.order.receiver;

import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.order.service.OrderInfoService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class OrderReceiver {


    @Autowired
    private OrderInfoService orderInfoService;

    /**
     * 监听支付成功
     * @param record
     */
    @KafkaListener(topics = KafkaConstant.QUEUE_ORDER_PAY_SUCCESS)
    public void orderPaySuccess(ConsumerRecord<String , String> record){
        //  获取发送的订单编号
        String outTradeNo = record.value();
        //  判断
        if (!StringUtils.isEmpty(outTradeNo)){
            orderInfoService.orderPaySuccess(outTradeNo);
        }
    }


}
